package org.ceteca.explica.client.gui;

import java.lang.reflect.Method;

import org.ceteca.explica.client.ClientContext;
import org.ceteca.explica.core.InterfaceErrors;
import org.ceteca.explica.core.util.OperationResult;

public class GUIOperation implements Runnable {
	private Method method;
	private Object instance;
	private Object[] params;
	private OperationResult result;
	
	public GUIOperation(Method method, Object instance, Object[] params) {
		this.method = method;
		this.instance = instance;
		this.params = params;
	}
	
	public void run() {
		if (this.method != null && this.instance != null) {
			try {
				this.method.invoke(this.instance, this.params);
				result = new OperationResult();
				result.setResult(OperationResult.RESULT_OK);
			}
			catch (Exception ex) {
				result = new OperationResult();
				result.addResultMessage(OperationResult.RESULT_ERROR, 
						ClientContext.getInstance().getMsgCatalog().newResultMessage(InterfaceErrors.ERR_GUI_OPERATION_ERROR, ex));
			}
		}
	}

}
